home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / ezy_comm / ezy1023.zip / EKIT102.ZIP / EZYINC.PAS < prev    next >
Pascal/Delphi Source File  |  1992-10-24  |  13KB  |  552 lines

  1. (* EZYINC V1.00 - An Ezycom General Purpose TP Unit
  2.  
  3.    Copyright Peter Davies 1992.  All Rights Reserved.
  4.  
  5.    This source may be freely used as long as due credit is given.
  6.    That means, in your documentation, you MUST acknowledge that
  7.       "EZYINC Copyright Peter Davies 1992" was used.
  8.  
  9.    EZYINC is a general purpose unit for Ezycom Utilities
  10.    Simply add EZYINC to your uses statement
  11.  
  12.    Features: General Purpose Procedures
  13.              Automatic Reading of CONFIG.EZY into configrec
  14.              -N<node> and/or TASK aware
  15.                 (node number stored in "node")
  16.              Inline Assembly on highly used routines *)
  17.  
  18. unit ezyinc;
  19.  
  20. {$F+,R-,S-,V-}
  21. Interface
  22.  
  23. uses Crt, dos;
  24.  
  25. {$I struct}
  26.  
  27. procedure setbit(position, value : byte; var changebyte : byte);
  28. procedure setbitbyte(position : byte;value : boolean;var changebyte : byte);
  29.    (* Set a Bit at Position <0-7> to On=1 or Off=0 *)
  30.  
  31. procedure setbitword(position : byte;value : boolean; var changeword : word);
  32.    (* Set a Bit at Position <0-15> to Value *)
  33.  
  34. function biton(position : byte;testword : word) : boolean;
  35.    (* Test if Bit Position <0-15> is on in TestWord
  36.       Note: Also works on Bytes *)
  37.  
  38. function itospad(x : longint;padout : byte) : str12;
  39.    (* Returns a String from a Number, padded with leading 0s padout size *)
  40.  
  41. function itos(x : longint) : str12;
  42.    (* Returns a String from a Number *)
  43.  
  44. function dig2(s : word) : str2;
  45.    (* Return a 2 Digit String ranging 00 to 99 *)
  46.  
  47. function low2up(line : maxstr) : maxstr;
  48.    (* Convert Lowercase to Uppercase *)
  49.  
  50. function find(path : maxstr) : boolean;
  51.    (* Returns True if PATH exists *)
  52.  
  53. function findw(s : maxstr) : maxstr;
  54.    (* Returns the Path and filename of a Configuration File(s) *)
  55.  
  56. function parfind(line : maxstr) : boolean;
  57.    (* Returns true if it finds LINE in the parameters *)
  58.  
  59. function getparam(line : maxstr) : string;
  60.    (* Returns the remaining portion of LINE in paramaters *)
  61.  
  62. function st_trail(s : maxstr) : maxstr;
  63.    (* Strips Trailing Spaces *)
  64.  
  65. function addslash(line : maxstr) : maxstr;
  66.    (* Adds a Slash if not there to LINE *)
  67.  
  68. function remslash(line : maxstr) : maxstr;
  69.    (* Removes the Slash if there in LINE *)
  70.  
  71. function checkdate(yy,mm,dd : word) : boolean;
  72.    (* Checks for a Valid Date *)
  73.  
  74. function wordtodate(temp : word;var yy,mm,dd : word) : boolean;
  75.    (* Converts a Word to Date Format *)
  76.  
  77. function datetoword(yy,mm,dd : word) : word;
  78.    (* Converts a Date to a Word Format *)
  79.  
  80. function st_lead(s : maxstr) : maxstr;
  81.    (* Removes leading SPACES from a string *)
  82.  
  83. function retmessxxx(msgboard : word;t : byte) : maxstr;
  84.    (* Returns the FULL path to a message area
  85.       On entry if T = 1 then the Header Path is returned
  86.                if T = 2 then the Text   Path is returned *)
  87.  
  88. function retfilexxx(filearea : word) : maxstr;
  89.    (* Returns the FULL path to a file area *)
  90.  
  91. var
  92.    systempath : maxstr;           { Path to System Files   }
  93.    node       : byte;             { Node Number -N<1..250> }
  94.    configrec  : configrecord;     { Configuration          }
  95.    constant   : constantrecord;   { Constant               }
  96.  
  97. implementation
  98.  
  99.  
  100. {$IFDEF Ver60} (* if turbo pascal V6.0 *)
  101.  
  102. function biton(position : byte;testword : word) : boolean; assembler;
  103.  
  104. asm
  105.    mov ax, 1;
  106.    mov cl, position;
  107.    shl ax, cl;
  108.    and ax, testword;
  109.    jnz @notbiton
  110.    mov ax, false;
  111.    jmp @finish;
  112.    @notbiton :
  113.       mov ax, true;
  114.    @finish :
  115. end;
  116.  
  117. {$ELSE}
  118.  
  119. function biton(position : byte;testword : word) : boolean;
  120.  
  121. var
  122.    bt : word;
  123.  
  124. begin
  125.    bt := $01;
  126.    bt := bt shl position;
  127.    biton := (bt and testword) > 0;
  128. end;
  129.  
  130. {$ENDIF}
  131.  
  132. procedure setbitword(position : byte;value : boolean;var changeword : word);
  133.    (* Set a Bit at Position <0-15> to Value *)
  134.  
  135. var
  136.    wd : word;
  137.  
  138. begin
  139.    wd := $01;
  140.    wd := wd shl position;
  141.    if value then
  142.       changeword := changeword or wd else
  143.       begin
  144.          wd := wd xor $ff;
  145.          changeword := changeword and wd;
  146.       end;
  147. end;
  148.  
  149. procedure setbitbyte(position : byte;value : boolean;var changebyte : byte);
  150.    (* Set a Bit at Position <0-7> to Value *)
  151.  
  152. var
  153.    wd : byte;
  154.  
  155. begin
  156.    wd := $01;
  157.    wd := wd shl position;
  158.    if value then
  159.       changebyte := changebyte or wd else
  160.       begin
  161.          wd := wd xor $ff;
  162.          changebyte := changebyte and wd;
  163.       end;
  164. end;
  165.  
  166.  
  167. procedure setbit(position, value : byte; var changebyte : byte);
  168.  
  169. var
  170.    bt : byte;
  171.  
  172. begin
  173.    bt := $01;
  174.    bt := bt shl position;
  175.    if value = 1 then
  176.       changebyte := changebyte or bt else
  177.       begin
  178.          bt := bt xor $ff;
  179.          changebyte := changebyte and bt;
  180.       end;
  181. end;
  182.  
  183. function find(path : maxstr) : boolean;
  184.  
  185. var
  186.    srec : searchrec;
  187.  
  188. begin
  189.    findfirst(path,anyfile,srec);
  190.    find := (doserror = 0);
  191. end;
  192.  
  193. function itospad(x : longint;padout : byte) : str12;
  194.  
  195. var
  196.    temp : str12;
  197.  
  198. begin
  199.    str(x:padout,temp);
  200.    for padout := 1 to length(temp) do
  201.       if (temp[padout] = ' ') then
  202.          temp[padout] := '0';
  203.    itospad := temp;
  204. end;
  205.  
  206. function dig2(s : word) : str2;
  207.  
  208. begin
  209.    dig2 := itospad(s,2);
  210. end;
  211.  
  212. function ItoS(x : longint) : str12;
  213.  
  214. var
  215.    temp : string[12];
  216.  
  217. begin
  218.    str(x,temp);
  219.    itos := temp;
  220. end;
  221.  
  222. function low2up(line : maxstr) : maxstr;
  223.  
  224. {var
  225.    loop : integer;}
  226.  
  227. begin
  228. {   for loop := 1 to length(line) do      ***** Pascal Equivalent *****
  229.       line[loop] := upcase(line[loop]);
  230.    low2up := line;}
  231. INLINE(
  232.   $1E/
  233.   $C5/$76/$06/
  234.   $C4/$7E/$0A/
  235.   $FC/
  236.   $AC/
  237.   $AA/
  238.   $30/$ED/
  239.   $88/$C1/
  240.   $E3/$0E/
  241.   $AC/
  242.   $3C/$61/
  243.   $72/$06/
  244.   $3C/$7A/
  245.   $77/$02/
  246.   $2C/$20/
  247.   $AA/
  248.   $E2/$F2/
  249.   $1F);
  250. end;
  251.  
  252. function findw(s : maxstr) : maxstr;
  253.  
  254. begin
  255.    if find(systempath + s + '.' + itos(node)) then
  256.       findw := systempath + s + '.' + itos(node) else
  257.       if find(s + '.EZY') then
  258.          findw := s + '.EZY' else
  259.             findw := systempath + s + '.EZY';
  260. end;
  261.  
  262. function getparam(line : maxstr) : string;
  263.  
  264. var
  265.    loop     : integer;
  266.    found    : boolean;
  267.    posstart : byte;
  268.  
  269. begin
  270.    loop := 1;
  271.    found := false;
  272.    while (loop <= paramcount) and (not found) do
  273.       begin
  274.          posstart := pos(line,low2up(paramstr(loop)));
  275.          if (posstart = 1) then
  276.             found := true else
  277.             loop := loop + 1;
  278.       end;
  279.    if found then
  280.       getparam := copy(paramstr(loop),posstart+length(line),255) else
  281.       getparam := '';
  282. end;
  283.  
  284. function st_trail(s : maxstr) : maxstr;
  285.  
  286. {var
  287.    loop : integer;
  288.    alpha : boolean;}
  289.  
  290. begin
  291. {   alpha := false;
  292.    for loop := length(s) downto 1 do           **** Pascal Equivalent ****
  293.          if (s[loop] = ' ') and (not alpha) then
  294.             s[0] := chr(ord(s[0]) -1) else
  295.             alpha := true;
  296.    st_trail := s;              }
  297. INLINE(
  298.   $1E/
  299.   $C5/$76/$06/
  300.   $FC/
  301.   $AC/
  302.   $3C/$00/
  303.   $74/$21/
  304.   $30/$ED/
  305.   $88/$C1/
  306.   $B0/$20/
  307.   $C4/$7E/$06/
  308.   $01/$CF/
  309.   $FD/
  310.   $F3/$AE/
  311.   $74/$01/
  312.   $41/
  313.   $88/$C8/
  314.   $C5/$76/$06/
  315.   $46/
  316.   $C4/$7E/$0A/
  317.   $FC/
  318.   $AA/
  319.   $F2/$A4/
  320.   $E9/$04/$00/
  321.   $C4/$7E/$0A/
  322.   $AA/
  323.   $1F);
  324. end;
  325.  
  326. function st_lead(s : maxstr) : maxstr;
  327.  
  328. var
  329.    loop : word;
  330.    slength : byte absolute s;
  331.  
  332. begin
  333.    loop := 1;
  334.    while (loop <= slength) and (s[loop] = ' ') do
  335.       inc(loop);
  336.    dec(loop);
  337.    if (loop > 0) then
  338.       delete(s, 1, loop);
  339.    st_lead := s;
  340. end;
  341.  
  342. function addslash(line : maxstr) : maxstr;
  343.  
  344. var
  345.    llen : byte absolute line;
  346.  
  347. begin
  348.    line := st_trail(line);
  349.    if (llen > 0) and (line[llen] <> '\') then
  350.       begin
  351.          inc(llen);
  352.          line[llen] := '\';
  353.       end;
  354.    addslash := line;
  355. end;
  356.  
  357. function remslash(line : maxstr) : maxstr;
  358.  
  359. var
  360.    llen : byte absolute line;
  361.  
  362. begin
  363.    if (length(line) > 0) and (line[length(line)] = '\') then
  364.       dec(llen);
  365.    remslash := line;
  366. end;
  367.  
  368. function parfind(line : maxstr) : boolean;
  369.  
  370. var
  371.    loop : integer;
  372.    found : boolean;
  373.  
  374. begin
  375.    loop := 1;
  376.    found := false;
  377.    while (loop <= paramcount) and (not found) do
  378.       if pos(line,low2up(paramstr(loop))) = 1 then
  379.          found := true else
  380.          loop := loop + 1;
  381.    parfind := found;
  382. end;
  383.  
  384. function checkdate(yy,mm,dd : word) : boolean;
  385.  
  386. const
  387.    daysinmonth : array[1..12] of word =
  388.       (31,29,31,30,31,30,31,31,30,31,30,31);
  389.  
  390. begin
  391.    checkdate := false;
  392.    if (mm < 1) or (mm > 12) then
  393.       exit;
  394.    if (dd < 1) or (dd > daysinmonth[mm]) then
  395.       exit;
  396.    if not ((yy mod 4 <> 0) and (dd = 29) and (mm=2)) then
  397.       checkdate := true;
  398. end;
  399.  
  400.  
  401. function datetoword(yy,mm,dd : word) : word;
  402.  
  403. var
  404.    tofield        : word;
  405.    tempbyte       : byte;
  406.  
  407. begin
  408.    datetoword := 65535;
  409.    if not checkdate(yy,mm,dd) then
  410.       exit;
  411.    tofield := dd - 1;
  412.    tofield := tofield + ((mm - 1) shl 5);
  413.    if (yy < 1980) or (yy > (1980 + 127)) then
  414.       exit;
  415.    yy := yy - 1980;
  416.    tofield := tofield + (yy shl 9);
  417.    datetoword := tofield;
  418. end;
  419.  
  420. function wordtodate(temp : word;var yy,mm,dd : word) : boolean;
  421.  
  422. begin
  423.    if (temp = 65535) then
  424.       begin
  425.          wordtodate := false;
  426.          exit;
  427.       end else
  428.          wordtodate := true;
  429.    dd   := temp and 31 + 1;
  430.    temp := temp shr 5;
  431.    mm   := temp and 15 + 1;
  432.    temp := temp shr 4;
  433.    yy   := (temp and 127) + 1980;
  434. end;
  435.  
  436. function retmessxxx(msgboard : word;t : byte) : maxstr;
  437.  
  438. var
  439.    temp  : string[3];
  440.    temp2 : string[3];
  441.  
  442. begin
  443.    temp := itospad(msgboard,3);
  444.    str(((msgboard-1) div 100) + 1,temp2);
  445.    if t = 1 then
  446.       retmessxxx := configrec.msgpath + 'AREA' + temp2 + '\MSGH' + temp + '.BBS' else
  447.       retmessxxx := configrec.msgpath + 'AREA' + temp2 + '\MSGT' + temp + '.BBS';
  448. end;
  449.  
  450. function retfilexxx(filearea : word) : maxstr;
  451.  
  452. var
  453.    temp  : string[3];
  454.    temp2 : string[3];
  455.  
  456. begin
  457.    temp := itospad(filearea,3);
  458.    str(((filearea-1) div 100) + 1,temp2);
  459.    retfilexxx := configrec.filepath + 'AREA' + temp2 + '\FILE' + temp + '.BBS';
  460. end;
  461.  
  462. procedure newsetup;
  463.  
  464. var
  465.    tempfile   : file;
  466.    tempstr    : maxstr;
  467.    error      : integer;
  468.  
  469. begin
  470.    systempath := getenv('EZY');
  471.    if (length(systempath) = 0) then
  472.       getdir(0,systempath);
  473.    systempath := fexpand(addslash(low2up(systempath)));
  474.    node := 1;
  475.    tempstr := getenv('TASK');
  476.    if (length(tempstr) > 0) then
  477.       begin
  478.          val(tempstr,node,error);
  479.          if (error > 0) or (node = 0) then
  480.             node := 1 else
  481.          if (node > 250) then
  482.             node := 250;
  483.       end;
  484.    tempstr := getparam('-N');
  485.    if (length(tempstr) > 0) then
  486.       begin
  487.          val(tempstr,node,error);
  488.          if (error > 0) or (node = 0) then
  489.             node := 1 else
  490.          if (node > 250) then
  491.             node := 250;
  492.       end;
  493.    tempstr := findw('CONFIG');
  494.    if not find(tempstr) then
  495.       begin
  496.          if (doserror = 3) then
  497.             begin
  498.                writeln(chr(254) + ' System Path Invalid.');
  499.                writeln(chr(254) + ' Please Change EZY Environment Variable.');
  500.                halt(1);
  501.             end;
  502.          writeln(chr(254) + ' CONFIG.EZY not found');
  503.          writeln(chr(254) + ' Use CONFIG.EXE to Create it');
  504.          halt(1);
  505.       end;
  506.    if not find(systempath + 'CONSTANT.EZY') then
  507.       begin
  508.          writeln(chr(254) + ' CONSTANT.EZY not found');
  509.          writeln(chr(254) + ' Use CONFIG.EXE to Create it');
  510.          halt(1);
  511.       end;
  512.    filemode := fdenynone + freadonly;
  513.    assign(tempfile,systempath + 'CONSTANT.EZY');
  514.    {$I-}
  515.    repeat
  516.       reset(tempfile,sizeof(constantrecord));
  517.       error := ioresult;
  518.       if (error = 5) then
  519.          delay(500) else
  520.       if (error <> 0) then
  521.          runerror(error);
  522.    until (error = 0);
  523.    {$I+}
  524.    blockread(tempfile,constant,1);
  525.    close(tempfile);
  526.    filemode := fdenynone + freadonly;
  527.    assign(tempfile,tempstr);
  528.    {$I-}
  529.    repeat
  530.       reset(tempfile,sizeof(configrec));
  531.       error := ioresult;
  532.       if (error = 5) then
  533.          delay(500) else
  534.       if (error <> 0) then
  535.          runerror(error);
  536.    until (error = 0);
  537.    {$I+}
  538.    blockread(tempfile,configrec,1);
  539.    close(tempfile);
  540.    checksnow   := configrec.snow_check;
  541. end;
  542.  
  543.  
  544. begin
  545.    if (LastMode <> CO80) and (LastMode <> BW80) and
  546.       (LastMode <> Mono) then
  547.       TextMode(CO80);
  548.    directvideo := false;
  549.    textattr    := 7;
  550.    newsetup;
  551. end.
  552.